<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
        解题思路：
        1.分析需求：
        2.编写代码；
        3.调试代码.
         */
        //将数组 ['关羽', '张飞', '程咬金','吕布'] 转化为字符串
        var arr = ['关羽', '张飞', '程咬金', '吕布'];
        var result = "[";
        for (let index in arr) {
            // console.log(index, arr[index]);
            // result = result + "\'" + arr[index] + "\'" + ", ";
            // 最后一个元素单独处理
            if (index == arr.length - 1) {
                // console.log(arr[index] + "是最后一个元素");
                result = result + "\'" + arr[index] + "\'";
            } else {
                result = result + "\'" + arr[index] + "\'" + ", ";
            }
        }
        result = result + "]";
        console.log(result);
    </script>
</body>

</html>